import LayerClient from './src/layer';
import StyleClient from './src/style';
import WorkspaceClient from './src/workspace';
import DatastoreClient from './src/datastore';
import ImageMosaicClient from './src/imagemosaic';
import SecurityClient from './src/security';
import SettingsClient from './src/settings';
import NamespaceClient from './src/namespace';
import AboutClient from './src/about';
import ResetReloadClient from './src/reset-reload';
import LayerGroupClient from './src/layergroup';

export { GeoServerResponseError } from './src/util/geoserver'


/**
 * Client for GeoServer REST API.
 * Has minimal basic functionality and offers REST client instances for
 * sub-entities, like workspaces or datastores as member variables.
 *
 * @module GeoServerRestClient
 */
export class GeoServerRestClient {
  /**
   * Creates a GeoServerRestClient instance.
   *
   * @param {string} url The URL of the GeoServer REST API endpoint
   * @param {string} user The user for the GeoServer REST API
   * @param {string} password The password for the GeoServer REST API
   */
  constructor(public url: string, public user: string, public password: string) {
    this.url = this.url.endsWith('/') ? this.url : this.url + '/';
    this.auth = 'Basic ' + Buffer.from(this.user + ':' + this.password).toString('base64');

    this.layers = new LayerClient(this.url, this.auth);
    this.layergroups = new LayerGroupClient(this.url, this.auth);
    this.styles = new StyleClient(this.url, this.auth);
    this.workspaces = new WorkspaceClient(this.url, this.auth);
    this.namespaces = new NamespaceClient(this.url, this.auth);
    this.datastores = new DatastoreClient(this.url, this.auth);
    this.imagemosaics = new ImageMosaicClient(this.url, this.auth);
    this.security = new SecurityClient(this.url, this.auth);
    this.settings = new SettingsClient(this.url, this.auth);
    this.about = new AboutClient(this.url, this.auth);
    this.resetReload = new ResetReloadClient(this.url, this.auth);
  }

  private auth: string;

  public layers: LayerClient;
  public layergroups: LayerGroupClient;
  public styles: StyleClient;
  public workspaces: WorkspaceClient;
  public namespaces: NamespaceClient;
  public datastores: DatastoreClient;
  public imagemosaics: ImageMosaicClient;
  public security: SecurityClient;
  public settings: SettingsClient;
  public about: AboutClient;
  public resetReload: ResetReloadClient;
}